/*
* Copyright (c) 2006, obsoleet industries
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of obsoleet industries nor the names of its
*       contributors may be used to endorse or promote products derived from
*       this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


using libsecondlife;
using libsecondlife.Packets;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Meebey.SmartIrc4net;
using System.Text.RegularExpressions ;

namespace slirc
{
    partial class SlircNG
    {
        void parseIrcCommand(string message, string netmask)
        {
            bool master = false;
            bool access = false;
            Match m = Regex.Match(netmask, masterIrc);
            if ( m.Success)
            {
                master = true;
            }
            foreach (string thisNetmask in allowedIrc)
            {
                m = Regex.Match(netmask, thisNetmask);
                if (m.Success)
                {
                    access = true;
                    break;
                }
            }
            if (myClient.IsConnected)
            {
                string response = ParseCommand(message, access, master) ;
                if (response != null)
                {
                    char[] splitChar = { '\n' };
                    string[] messages = response.Split(splitChar);
                    foreach (string output in messages)
                    {
                        debug("IRC Chat output to " + ircChannel + " - [" + output.Length.ToString() + "] " + output, 5);
                        if (output != null && output.Length > 0 )
                        {
                            textOut(output, false, true, false);
                        }
                    }
                }
            }
        }
        void parseIrcCommand(string message, string netmask, string from)
        {
            bool master = false;
            bool access = false;
            debug("New PM IRC [" +netmask +"]", 5);
            Match m = Regex.Match(netmask, masterIrc);
            if ( m.Success)
            {
                master = true;
            }
            foreach (string thisNetmask in allowedIrc)
            {
                m = Regex.Match(netmask, thisNetmask);
                if (m.Success)
                {
                    access = true;
                    break;
                }
            }
            if (myClient.IsConnected)
            {
                string response = ParseCommand(message, access, master);
                if (response != null)
                {
                    char[] splitChar = { '\n' };
                    string[] messages = response.Split(splitChar);
                    foreach (string output in messages)
                    {
                        debug("IRC PM output to " + from + " - [" + output.Length.ToString() + "] " + output, 5);
                        if (output != null && output.Length > 0)
                        {
                            myClient.SendMessage(SendType.Message, from, output);
                        }
                    }
                }
            }
        }
        void parseSlCommand(string message, LLUUID key, LLUUID imSessionID)
        {
            bool master = false;
            bool access = false;
            debug("New command from SL(IM) [" +  key.ToString() + "]", 5);
            if (key == masterSL)
            {
                master = true;
            }
            foreach (LLUUID thisKey in allowedSL)
            {
                if (thisKey  == key )
                {
                    access = true;
                    break;
                }
            }
            if (Client.Network.Connected)
            {
                string response = ParseCommand(message, access, master);
                if (response != null)
                {
                    char[] splitChar = { '\n' };
                    string[] messages = response.Split(splitChar);
                    foreach (string output in messages)
                    {
                        debug("SL IM output to " + key.ToString() + " - [" + output.Length.ToString() + "] " + output, 5);
                        if (output != null && output.Length > 0)
                        {
                            Client.Self.InstantMessage(key, output, imSessionID);
                        }
                    }
                }
            }
        }
        void parseSlCommand(string message, LLUUID key)
        {
            bool master = false;
            bool access = false;
            debug("New command from SL [" + key.ToString() + "]", 5);
            if (key == masterSL)
            {
                master = true;
            }
            foreach (LLUUID thisKey in allowedSL)
            {
                if (thisKey == key)
                {
                    access = true;
                    break;
                }
            }
            if (Client.Network.Connected)
            {
                string response = ParseCommand(message, access, master);
                if (response != null)
                {
                    char[] splitChar = { '\n' };
                    string[] messages = response.Split(splitChar);
                    foreach (string output in messages)
                    {
                        debug("SL Chat output - [" + output.Length.ToString() + "] " + output, 5);
                        if (output != null && output.Length > 0)
                        {
                            textOut(output, false, false, true);
                        }
                    }
                }
            }
        }

        string ParseCommand(string message, bool access, bool master)
        {
            if (master)
            {
                access = true;
            }
            debug("   * Command - " + message, 5);
            if (message.Length == 0) return null;
            char[] splitChar = { ' ' };
            string[] msg = message.Split(splitChar);
            if (msg[0] == null || msg[0] == "") return null;
            string command = msg[0].ToLower();
            if (command.Substring(0, 1) == "/" || command.Substring(0, 1) == "!")
            {
                command = command.Substring(1);
            }
            else
            {
                return null;
            }
            string response = null;
            switch (command)
            {
                #region quit
                case "quit":
                    {
                        if (master)
                        {
                            logout = true;
                            response = "Shutting down...";
                        }
                        break;
                    }
                #endregion
                #region relog
                case "relog":
                    {
                        if (master)
                        {
                            response = "Relogging...";
                            Client.Network.Logout();
                            while (Client.Network.Connected)
                            {
                                Client.Tick();
                            }
                            while (!Login()) Thread.Sleep(5000);
                        }
                        break;
                    }
#endregion
                #region teleport
                case "teleport":
                    {
                        if (access)
                        {
                            campCheckTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                            response = parseTeleportCommand(msg);
                        }
                        break;
                    }
#endregion
                #region help
                case "help":
                    {
                        response = parseHelpCommand(access, master);
                        break;
                    }
                                    #endregion
                #region access
                case "access":
                    {
                        if (master)
                        {
                            response = parseAccessCommand(msg);
                        }
                        break;
                    }
                                    #endregion
                #region debug
                case "debug":
                    {
                        if (master)
                        {
                            response = parseDebugCommand(msg);
                        }
                        break;
                    }
#endregion
                #region sit
                case "sit":
                    {
                        if (access)
                        {
                            if (msg.Length == 2)
                            {
                                campCheckTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                                debug("Sitting on " + msg[1].ToString(), 4);
                                Client.Self.RequestSit((LLUUID)msg[1], new LLVector3());
                                Client.Self.Sit();
                                Client.Self.Status.Controls.FinishAnim = false;
                                Client.Self.Status.Controls.Fly = false;
                                Client.Self.Status.Controls.SitOnGround = false;
                                Client.Self.Status.Controls.StandUp = false;
                                Client.Self.Status.SendUpdate();
                            }
                            else
                            {
                                response = "Invalid syntax : sit UUID";
                            }
                        }
                        break;
                    }
#endregion
                #region sitg
                case "sitg":
                    {
                        if (access)
                        {
                            campCheckTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                            debug("Sitting on ground at " + Client.Self.Position.ToString(), 4);
                            Client.Self.Status.Controls.StandUp = false;
                            Client.Self.Status.Controls.SitOnGround = true;
                            Client.Self.Status.SendUpdate();
                        }
                        break;
                    }
#endregion
                #region stand
                case "stand":
                    {
                        if (access)
                        {
                            commandStand();
                        }
                        break;
                    }
#endregion
                #region time
                case "time":
                    {
                        response = RPGWeather();
                        break;
                    }
#endregion
                #region whisper
                case "whisper":
                    {
                        if (access && msg.Length > 1)
                        {
							Array.Clear(msg, 0, 1);
                            string details = normalizeString(msg);
                            response = "whispered " + details;
                            if (Client.Network.Connected)
                            {
                                Client.Self.Chat(details, 0, MainAvatar.ChatType.Whisper);
                            }
                            if (myClient.IsConnected)
                            {
                                myClient.SendMessage(SendType.Action, ircChannel, "*whispers* " + details);
                            }
                        }
                        break;
                    }
#endregion
                #region shout
                case "shout":
                    {
                        if (master && msg.Length > 1)
                        {
							Array.Clear(msg, 0, 1);
                            string details = normalizeString(msg);
                            response = "shouted " + details;
                            if (Client.Network.Connected)
                            {
                                Client.Self.Chat(details, 0, MainAvatar.ChatType.Shout);
                            }
                            if (myClient.IsConnected)
                            {
                                myClient.SendMessage(SendType.Action, ircChannel, "*shouts* " + details);
                            }
                        }
                        break;
                    }
#endregion
                #region say
                case "say":
                    {
                        if (access && msg.Length > 1)
                        {
							Array.Clear(msg, 0, 1);
                            string details = normalizeString(msg);
                            response = "said " + details;
                            if (Client.Network.Connected)
                            {
                                Client.Self.Chat(details, 0, MainAvatar.ChatType.Normal);
                            }
                            if (myClient.IsConnected)
                            {
                                myClient.SendMessage(SendType.Message, ircChannel, details);
                            }
                        }
                        break;
                    }
#endregion
                #region location
                case "location":
                    {
                        if (access)
                        {
                            response = "Located in " + Client.Network.CurrentSim.Region.Name.ToString() + " at " + Client.Self.Position.ToString() + ".";
                        }
                        break;
                    }
#endregion
                #region relay
                case "relay":
                    {
                        if (msg.Length == 2)
                        {

                            if (access)
                            {
                                try
                                {
                                    relayChat = Boolean.Parse(msg[1]);
                                }
                                catch
                                {
                                    //do nothing
                                }
                            }
                        }
                        response = ("Relay is set to " + relayChat.ToString());
                    }
                    break;
#endregion
                #region sl
                case "sl":
                    {
                        if (msg.Length == 2)
                        {
                            if (access)
                            {
                                try
                                {
                                    relaySL = Boolean.Parse(msg[1]);
                                }
                                catch
                                {
                                    //do nothing
                                }
                            }
                        }
                        response = "SL forwarding is set to " + relaySL.ToString();
                    }
                    break;
#endregion
                #region irc
                case "irc":
                    {
                        if (msg.Length == 2)
                        {
                            if (access)
                            {
                                try
                                {
                                    relayIRC = Boolean.Parse(msg[1]);
                                }
                                catch
                                {
                                    //do nothing
                                }
                            }
                        }
                        response = "IRC forwarding is set to " + relayIRC.ToString();
                    }
                    break;
#endregion
                #region uniquenick
                case "uniquenick":
                    {
                        if (msg.Length == 2)
                        {
                            if (master)
                            {
                                try
                                {
                                    uniqueIRCNick = Boolean.Parse(msg[1]);
                                    if (uniqueIRCNick)
                                    {
                                        foreach (avatarCache thisAvatar in avatars)
                                        {
                                            if ((Helpers.VecDist(thisAvatar.pos, Client.Self.Position) < 20) && (thisAvatar.name != Client.Self.FirstName + " " + Client.Self.LastName))
                                            {
                                                bool check = ircConnect(thisAvatar.key, thisAvatar.name, false);
                                                if (!check)
                                                {
                                                    debug("Unable to add " + thisAvatar.name + " to IRC", 2);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        foreach (KeyValuePair<LLUUID, Thread> dictEnum in listenthreads)
                                        {
                                            dictEnum.Value.Abort();
                                        }
                                        foreach (KeyValuePair<LLUUID, IrcClient> dictEnum in ircconns)
                                        {
                                            dictEnum.Value.RfcQuit("switching to aggregate mode");
                                        }
                                    }
                                }

                                catch
                                {
                                    //do nothing
                                }
                            }
                        }
                        response = ("Unique IRC Nicks is set to " + uniqueIRCNick.ToString());
                    }
                    break;
#endregion
                #region who
                case "who":
                    {
                        if (avatars.Count == 0)
                        {
                            response = "No one is around";
                        }
                        else
                        {
                            foreach (avatarCache thisAvatar in avatars)
                            {
                                response = response + thisAvatar.name + " (" + (int)Helpers.VecDist(Client.Self.Position, thisAvatar.pos) + "m) at " + thisAvatar.pos.ToString() + "\n";
                            }
                        }
						if ( msg.Length == 2 ) {
							if ( msg[1] == "force" ) {
								break;
							}
						}
						if (avatars.Count > 5 ) {
							response = "There are " + avatars.Count.ToString() + " avatars present. If you sure, use !who force.";
						}
                    }
                    break;

                #endregion
                #region camp
                case "camp":
                    {
                        if (access)
                        {
                            response = parseCampCommand(msg);
                        }
                        break;
                    }
                #endregion

            }



            if (response == null) return null;
            return response;
        }
        string parseTeleportCommand(string[] msg)
        {
            if (msg.Length < 2)
            {
                return "Invalid Syntax : teleport sim [x y z]";
            }
			Array.Clear(msg,0,1);
            string simName;
            LLVector3 tPos;
            if (msg.Length >= 5)
            {
                simName = String.Join(" ", msg, 1, msg.Length - 4);
                float x = float.Parse(msg[msg.Length - 3]);
                float y = float.Parse(msg[msg.Length - 2]);
                float z = float.Parse(msg[msg.Length - 1]);
                tPos = new LLVector3(x, y, z);
            }
            else
            {
                simName = normalizeString(msg);
                tPos = new LLVector3(128, 128, 0);
            }
            Client.Self.Teleport(simName, tPos);
            debug("Attempting teleport to " + simName, 3);
			teleportEvent.WaitOne(300, false);
			teleportEvent.Reset();
			for (int i = 0; i < 30; i++)
			{
				debug("Current Sim - " + Client.Network.CurrentSim.Region.Name + " Dest Sim -  " + simName);
				if (Client.Network.CurrentSim.Region.Name.ToLower() == simName.ToLower()) break;
				Thread.Sleep(100);
			}
			if ( Client.Network.CurrentSim.Region.Name == simName ) {
				return "Successfully teleported to " + simName + " .";
			} else {
				return "Teleport was not successfull.";
			}
        }
        string parseDebugCommand(string[] msg)
        {
            string response = null;
            if (msg.Length == 2)
            {
                if (msg[1].ToLower() == "help")
                {
                    response = "debug [[true|false]|[sl|console|irc]] [true|false]";
                }
                else if (msg[1].ToLower() == "sl")
                {
                    response = "Debug on SL Chat is set to " + debugChat.ToString();
                }
                else if (msg[1].ToLower() == "irc")
                {
                    response = "Debug on IRC is set to " + debugIrc.ToString();
                }
                else if (msg[1].ToLower() == "console")
                {
                    response = "Debug on console is set to " + debugConsole.ToString();
                }
                else if (msg[1].ToLower() == "level")
                {
                    response = "Debug level is set to " + debugLevel.ToString();
                }
                else
                {
                    try
                    {
                        Debug = Boolean.Parse(msg[1]);
                    }
                    catch
                    {
                        //do nothing
                    }
                }
            }
            else if (msg.Length == 3)
            {
                if (msg[1].ToLower() == "sl")
                {
                    try
                    {
                        debugChat = Boolean.Parse(msg[2]);
                    }
                    catch
                    {
                        //nothing
                    }
                }
                else if (msg[1].ToLower() == "console")
                {
                    try
                    {
                        debugConsole = Boolean.Parse(msg[2]);
                    }
                    catch
                    {
                        //nothing
                    }
                }
                else if (msg[1].ToLower() == "irc")
                {
                    try
                    {
                        debugIrc = Boolean.Parse(msg[2]);
                    }
                    catch
                    {
                        //nothing
                    }
                }
                else if (msg[1].ToLower() == "level")
                {
                    int tempInt = debugLevel;
                    try
                    {
                        tempInt = Int32.Parse(msg[2]);
                    }
                    catch
                    {
                        //
                    }
                    if (6 > tempInt && tempInt > 0)
                    {
                        debugLevel = tempInt;
                    }
                }
            }
            //generate response if not done already
            if (response == null)
            {
                string buildResponse = null;
                buildResponse = "Debug is ";
                if (Debug)
                {
                    buildResponse = buildResponse + "enabled";
                    buildResponse = buildResponse + " on the following media [ ";
                    if (debugChat)
                    {
                        buildResponse = buildResponse + "[SL]";
                    }
                    if (debugIrc)
                    {
                        buildResponse = buildResponse + "[IRC]";
                    }
                    if (debugConsole)
                    {
                        buildResponse = buildResponse + "[Console]";
                    }
                    buildResponse = buildResponse + " ] Level - " + debugLevel.ToString();
                }
                else
                {
                    buildResponse = buildResponse + "disabled";
                }
                response = buildResponse;
            }
            return response;
        }
        string parseAccessCommand(string[] msg)
        {
            if (msg.Length >= 2)
            {
#region irc
                if ( msg[1].ToLower() == "irc" ) {
                    if ( msg.Length == 4 && msg[2].ToLower() == "add" ) {
                        allowedIrc.Add(msg[3]);
                        return "added " + msg[3] + " to irc acl";
                    } else if ( msg.Length == 4 && msg[2].ToLower() == "remove" ) {
                        if ( allowedIrc.Contains(msg[3]) ){
                            allowedIrc.Remove(msg[3]);
                            return "removed " + msg[3] + " from irc acl";
                        }
                        return "did not find " + msg[3] + " in irc acl";
                    } else {
                        if ( allowedIrc.Count > 0 ) {
                            string response = null;
                            foreach ( string thisEntry in allowedIrc ) {
                                response += thisEntry + "\n";
                            }
                            return response;
                        } 
                        return "irc acl empty";
                    }
                }
#endregion
#region sl
                else if ( msg[1].ToLower() == "sl" ) {
                    if ( msg.Length == 4 && msg[2].ToLower() == "add" ) {
                        try {
                            allowedSL.Add(msg[3]);
                        } catch {
                            return "invalid syntax = specify a key";
                        }
                        return "added " + msg[3] + " to sl acl";
                    } else if ( msg.Length == 4 && msg[2].ToLower() == "remove" ) {
                        if ( allowedSL.Contains(msg[3]) ) {
                            allowedSL.Remove(msg[3]);
                            return "removed " + msg[3] + " from sl acl";
                        }
                        return "did not find " + msg[3] + " in sl acl";
                    } else {
                        if ( allowedSL.Count > 0 ) {
                            string response = null;
                            foreach ( LLUUID thisEntry in allowedSL ) {
                                response += thisEntry.ToString() + "\n";
                            }
                            return response;
                        }
                        return "sl acl empty";
                    }
#endregion
#region file
                } else if ( msg[1].ToLower() == "save" ) {
                    bool check = writeAcl(aclFile);
                    if ( check ) {
                        return "ACL Written succesfully.";
                    } else {
                        return "ACL Not Written.";
                    }
                }
                else if (msg[1].ToLower() == "rehash" || msg[1].ToLower() == "load")
                {
                    bool check = readAcl(aclFile);
                    if (check)
                    {
                        return "ACL Loaded succesfully.";
                    }
                    else
                    {
                        return "ACL Not Loaded - nothing changed";
                    }
                }
                    #endregion
                return "access [irc|sl] [add|remove] [netmask] [key]";
            }
            return "access [irc|sl] [add|remove] [netmask] [key]";
        }
        string parseCampCommand(string[] msg)
        {
            if (msg.Length > 2)
            {
                if (msg[1] == "add" && msg.Length >= 7)
                {
                    campPosition newCamp = new campPosition();
                    try
                    {
                        newCamp.name = msg[2];
                        newCamp.key = new LLUUID(msg[msg.Length - 1]);
                        newCamp.pos = new LLVector3(float.Parse(msg[msg.Length - 4]), float.Parse(msg[msg.Length - 3]), float.Parse(msg[msg.Length - 2]));
                        string simName = null;
                        for (int i = 3; i < msg.Length - 4; i++)
                        {
                            simName = simName + msg[i];
                        }
                        newCamp.sim = simName;
                        camps.Add(newCamp);
                        return "Added " + newCamp.name + " to camp list";
                    }
                    catch
                    {
                        return "Syntax Error : camp add name sim name x y z key";
                    }
                }
                else if (msg[1] == "remove" && msg.Length == 3)
                {
                    foreach (campPosition thisCamp in camps)
                    {
                        if (thisCamp.name == msg[2])
                        {
                            camps.Remove(thisCamp);
                            return "Removed " + thisCamp.name + " from camp list.";
                        }
                    }
                    return "Did not find " + msg[2] + " in camp list.";
                }
                else
                {
                    return null;
                }
            }
            else
            {
                if (msg[1] == "list")
                {
                    string response = null;
                    foreach (campPosition thisPosition in camps)
                    {
                        response = response + thisPosition.name + " - " + thisPosition.sim + "@" + thisPosition.pos.ToString() + " on " + thisPosition.key.ToString() + "\n";
                    }
                    return response;
                }
                else if (msg[1] == "load" || msg[1] == "rehash")
                {
                    bool check = readCamps(campFile);
                    if (check)
                    {
                        return "Succesfully read in camps file.";
                    }
                    else
                    {
                        return "Did not read in camps file.";
                    }
                }
                else if (msg[1] == "save")
                {
                    bool check = writeCamp(campFile);
                    if (check)
                    {
                        return "Succesfully saved camps.";
                    }
                    else
                    {
                        return "Failed to save camps.";
                    }
                }
                else
                {
                    string details = null;
                    if (msg.Length == 1)
                    {
                        details = "home";
                    }
                    else
                    {
                        for (int i = 1; i < msg.Length; i++)
                        {
                            details = details + msg[i];
                        }
                    }
                    bool check = camp(details);
                    if (check)
                    {
                        return "camped succesfully at " + details;
                    }
                    else
                    {
                        return "camping failed at " + details;
                    }
                }
            }
        }
        string parseHelpCommand(bool access, bool master)
        {
            string response = null;
            response += "** slirc-ng help (command keys are ! and/or /)\n";
            if (master) response += "quit - shut down the application\n";
            if (master) response += "relog - relog sl\n";
            if (access) response += "teleport simName [x y z] - teleport to a specific location\n";
            if (master) response += "access [irc|sl|save|load] [add|remove] [netmask] [key] - controls ACL during runtime\n";
            if (master) response += "debug [[true|false]|[sl|console|irc]] [true|false]\n";
            if (access) response += "sit key - sit no the specified object\n";
            if (access) response += "sitg - sit on the ground at current location\n";
            if (access) response += "stand - stand up\n";
            response += "time - rough time, location\n";
            if (access) response += "whisper message - whisper\n";
            if (access) response += "say message - speak\n";
            if (access) response += "shout message - shout\n";
            if (access) response += "location - current location\n";
            if (access || master )
            {
                response += "relay [true|false] - enable/disable relay operation\n";
            }
            else
            {
                response += "relay - show forward status\n";
            }
            if (access || master)
            {
                response += "irc [true|false] - enable/disable IRC->SL relay\n";
            }
            else
            {
                response += "irc - show irc forward status\n";
            }
            if (access || master)
            {
                response += "sl [true|false] - enable/disable SL->IRC relay\n";
            }
            else
            {
                response += "sl - show sl forward status\n";
            }
            if (master) response += "uniquenick [true|false] - enable/disable Unique Nick support (buggy)\n";
            response += "who - list nearby avatars\n";
            if (access)
            {
                response += "camp [add|remove|save|load] - add / remove new camp spot or save/load file\n";
            }
            else if (master)
            {
                response += "camp [add|remove] - add / remove new camp spot\n";
            }
            return response;
        }
        void commandStand()
        {
            campCheckTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
            debug("Standing up", 4);
            Client.Self.Status.Controls.SitOnGround = false;
            Client.Self.Status.Controls.StandUp = true;
            Client.Self.Status.SendUpdate();
            Client.Self.Status.Controls.StandUp = false;
            Client.Self.Status.SendUpdate();
            //SendAgentAnimation((LLUUID)"2408fe9e-df1d-1d7d-f4ff-1384fa7b350f", true); //stand
        }


    }
}